package com.wondertek.poms.init.message;

import com.fasterxml.jackson.annotation.JsonInclude;

import lombok.Data;

@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ResultBean {
    /**
     * 信息代码
     */
    private String code;
    /**
     * 信息说明
     */
    private String msg;
    /**
     * 返回数据或jqgrid中的root
     */
    private Object result;


    private Integer total;

    private Long totalCount;

    public ResultBean() {
        
    }
    
    public ResultBean(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public ResultBean(String code, String msg, Object result) {
        this.code = code;
        this.msg = msg;
        this.result = result;
    }

    public static ResultBean ok() {
        return new ResultBean(MessageCodes.M880001 + "", MessageCodes.get(MessageCodes.M880001));
    }

    public static ResultBean ok(Object result) {
        return new ResultBean(MessageCodes.M880001 + "", MessageCodes.get(MessageCodes.M880001), result);
    }
    
    public Boolean isSuccess() {
        return (MessageCodes.M880001 + "").equals(this.code);
    }

    public static ResultBean error(){
        return new ResultBean(MessageCodes.M880000 + "", MessageCodes.get(MessageCodes.M880000));
    }

    public static ResultBean error(String msg){
        return new ResultBean(MessageCodes.M880000 + "", msg);
    }

    public static ResultBean error(String code, String msg){
        return new ResultBean(code, msg);
    }
    
    public static ResultBean error(int code){
        return new ResultBean(code + "", MessageCodes.get(code));
    }

    public ResultBean(String code) {
        this.code = code;
    }


    public ResultBean(String code, String msg, int total, long totalCount, Object result) {
        this.code = code;
        this.msg = msg;
        this.total = total;
        this.totalCount = totalCount;
        this.result = result;
    }


    public static ResultBean ok(Object result, int total, long totalCount) {
        return new ResultBean(MessageCodes.M880001 + "", MessageCodes.get(MessageCodes.M880001), total, totalCount,
                result);
    }

}
